# gozerbot/xmpp/monitor.py
#
#

""" monitors .. call callback on bot output. """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from gozerbot.utils.exception import handle_exception
from gozerbot.monitor import Monitor
from gozerbot.config import config
from gozerbot.eventbase import EventBase
from message import Message

class XMPPmonitor(Monitor):

    """ monitor jabber output """

    def handle(self, bot, event):

        """ fire jabber monitor callbacks. """

        try:
            #event.fromm = event['from'] = event.to
            e = Message()
            e.copyin(event)
            e.isreply = True
            e.iscmnd = True
            e.remotecmnd = True
            e.remoteout = bot.jid
            e.channel = event.to
            e.fromm = e['from'] = bot.jid
            e.nick = bot.nick
            e.botoutput = True
            Monitor.handle(self, bot, e)
        except AttributeError:
            handle_exception()

# xmpp monitor
xmppmonitor = XMPPmonitor('xmppmonitor')
